package com.trickytriads.utils
{	
	import flash.utils.setTimeout;
	
	import mx.rpc.AsyncToken;
	import mx.rpc.events.ResultEvent;
	
	/**
	 * Utility class for generating asynchronous operation responses.
	 **/
	public class AsyncTokenGenerator
	{
		public static function MakeToken (result:Object) : AsyncToken
		{
			var token:AsyncToken = new AsyncToken();
			setTimeout(ApplyResult, Math.random() * 500, token, result);
			return token;
		}
		
		public static function ApplyResult (token:AsyncToken, result:Object) : void
		{			
			mx_internal:token.setResult(result);
			var event:ResultEvent = new ResultEvent(ResultEvent.RESULT, false, true, result, token);
     		mx_internal:token.applyResult(event);
		}

	}
}